<?php
/**
 *  @file : datarelation.php
 *  @msg : 数据关联
 *  @date : 2015-01-05
 */
namespace haibao\cms\business;
class DataRelation extends \haibao\cms\business\Base{
	
	/**
	 * @table : ImageStar
	 * @msg : 设置图片与明星关联
	 * @param ： object \haibao\cms\model\data\ImageLibrary $imageModel 
	 * @param ： object \haibao\cms\model\data\Celebrity $starModel
	 */
	public static function setImageCelebrity($imageModel, $celebrityModel){
		
		self::checkOperation(self::FUNC_CODE_DATA_ASSOCIATION_SET_IMAGE_CELEBRITY);
		if(!$imageModel->Id){
			throw new BusinessException('图片ID为空',self::DATA_EMPTY);
		}
		if(!$celebrityModel->Id){
			throw new BusinessException('明星ID为空',self::DATA_EMPTY);
		}
		
		try {
			$data  = new \haibao\cms\data\DataRelation();
			$data->addImageCelebrity($imageModel->Id, $celebrityModel->Id);
		
		}catch (\Exception $e){
			throw new BusinessException($e->getMessage(),$e->getCode());
		}
	}
		
	/**
	 * @table : ImageProduct
	 * @msg : 设置图片与单品关联
	 * @param ： object \haibao\cms\model\data\ImageLibrary $imageModel 
	 * @param ： object \haibao\cms\model\data\Product $productModel
	 */
	public static function setImageProduct($imageModel, $productModel){

		self::checkOperation(self::FUNC_CODE_DATA_ASSOCIATION_SET_IMAGE_PRODUCT);
		if(!$imageModel->Id){
			throw new BusinessException('图片ID为空',self::DATA_EMPTY);
		}
		if(!$productModel->Id){
			throw new BusinessException('单品ID为空',self::DATA_EMPTY);
		}
		
		try {
			$data  = new \haibao\cms\data\DataRelation();
			$data->addImageProduct($imageModel->Id, $productModel->Id);
		
		}catch (\Exception $e){
			throw new BusinessException($e->getMessage(),$e->getCode());
		}
	}
	
	/**
	 * @table : ImageBrand
	 * @msg : 设置图片与品牌关联
	 * @param ： object \haibao\cms\model\data\ImageLibrary $imageModel
	 * @param ： object \haibao\cms\model\data\Product $brandModel
	 */
	public static function setImageBrand($imageModel, $brandModel){
	
		self::checkOperation(self::FUNC_CODE_DATA_ASSOCIATION_SET_IMAGE_BRAND);
		if(!$imageModel->Id){
			throw new BusinessException('图片ID为空',self::DATA_EMPTY);
		}
		if(!$brandModel->Id){
			throw new BusinessException('品牌ID为空',self::DATA_EMPTY);
		}
	
		try {
			$data  = new \haibao\cms\data\DataRelation();
			$data->addImageBrand($imageModel->Id, $brandModel->Id);
	
		}catch (\Exception $e){
			throw new BusinessException($e->getMessage(),$e->getCode());
		}
	}

	/**
	 * @table : ImageEvent
	 * @msg : 设置图片与事件关联（考虑关联关系 1对多？？）
	 * @param ： object \haibao\cms\model\data\ImageLibrary $imageModel
	 * @param ： object \haibao\cms\model\data\Event $eventModel
	 */
	public static function setImageEvent($imageModel, $eventModel){
	
		self::checkOperation(self::FUNC_CODE_DATA_ASSOCIATION_SET_IMAGE_EVENT);
		if(!$imageModel->Id){
			throw new BusinessException('图片ID为空',self::DATA_EMPTY);
		}
		if(!$eventModel->Id){
			throw new BusinessException('事件ID为空',self::DATA_EMPTY);
		}
	
		try {
			$data  = new \haibao\cms\data\DataRelation();
			$data->addImageEvent($imageModel->Id, $eventModel->Id);
	
		}catch (\Exception $e){
			throw new BusinessException($e->getMessage(),$e->getCode());
		}
	}
	
	/**
	 * @table : EventBrand
	 * @msg : 设置事件与品牌关联
	 * @param ：Int or Array $eventId 
	 * @param ： Int or Array $brandId
	 * @param ：Boolern $firstIsInt 表示方法的第几个参数为整形
	 */
	public static function setEventBrand($eventId, $brandId, $firstIsInt = true){

		self::checkOperation(self::FUNC_CODE_DATA_ASSOCIATION_SET_EVENT_BRAND);
		if(!$eventId){
			throw new BusinessException('事件ID为空',self::DATA_EMPTY);
		}
		if(!$brandId){
			throw new BusinessException('品牌ID为空',self::DATA_EMPTY);
		}
	

		$data  = new \haibao\cms\data\DataRelation();
		if($firstIsInt){
			$data->addEventBrand($eventId, $brandId);
		}else{
			$data->addBrandEvent($brandId, $eventId);
		}
	}
	
	/**
	 * @table : EventStar
	 * @msg : 设置事件与明星关联
	 * @param ：Int or Array $eventId 
	 * @param ： Int or Array $starId
	 * @param ：Boolern $firstIsInt 表示方法的第几个参数为整形
	 */
	public static function setEventStar($eventId, $starId, $firstIsInt = true){
	
		self::checkOperation(self::FUNC_CODE_DATA_ASSOCIATION_SET_EVENT_BRAND);
		if(!$eventId){
			throw new BusinessException('事件ID为空',self::DATA_EMPTY);
		}
		if(!$starId){
			throw new BusinessException('明星ID为空',self::DATA_EMPTY);
		}
		$data  = new \haibao\cms\data\DataRelation();
		if($firstIsInt){
			$data->addEventStar($eventId, $starId);
		}else{
			$data->addStarEvent($starId, $eventId);
		}
	}
	
	/**
	 * @table : EventProduct
	 * @msg : 设置单品与明星关联
	 * @param ： object \haibao\cms\model\data\Product $productModel
	 * @param ： object \haibao\cms\model\data\Celebrity $celebrityModel
	 */
	public static function setProductStar($productModel, $celebrityModel ){
	
		self::checkOperation(self::FUNC_CODE_DATA_ASSOCIATION_SET_EVENT_BRAND);
		if(!$celebrityModel->Id){
			throw new BusinessException('明星ID为空',self::DATA_EMPTY);
		}
		if(!$productModel->Id){
			throw new BusinessException('单品ID为空',self::DATA_EMPTY);
		}
	
		try {
			$data  = new \haibao\cms\data\DataRelation();
			$data->addProductStar($productModel->Id, $celebrityModel->Id);
	
		}catch (\Exception $e){
			throw new BusinessException($e->getMessage(),$e->getCode());
		}
	}
	
	/**
	 * @table : EventProduct
	 * @msg : 设置单品与事件关联
	 * @param ： object \haibao\cms\model\data\Event $eventModel
	 * @param ： object \haibao\cms\model\data\Product $productModel
	 */
	public static function setEventProduct($eventModel, $productModel){
	
		self::checkOperation(self::FUNC_CODE_DATA_ASSOCIATION_SET_EVENT_BRAND);
		if(!$eventModel->Id){
			throw new BusinessException('事件ID为空',self::DATA_EMPTY);
		}
		if(!$productModel->Id){
			throw new BusinessException('单品ID为空',self::DATA_EMPTY);
		}
	
		try {
			$data  = new \haibao\cms\data\DataRelation();
			$data->addEventProduct($eventModel->Id, $productModel->Id);
	
		}catch (\Exception $e){
			throw new BusinessException($e->getMessage(),$e->getCode());
		}
	}
	
}